class Solution {
    public static void main(String[] args) {
        int[] arr = {4,8,12,16} ;
        System.out.println(maxTurbulenceSize(arr
        ));
    }
    public static int maxTurbulenceSize(int[] arr) {
          
          int len = arr.length ;
          if(len <= 1) return len ; 
          int[] dp = new int[len];
          dp[0] = 1 ;
          dp[1] = arr[0]==arr[1]?1:2 ;
          int max = dp[1];
          for(int i=2 ; i < len ; i ++){
               if(arr[i] > arr[i-1]){
                 dp[i] = arr[i-1]<arr[i-2]?dp[i-1]+1:2 ;
               }else if(arr[i] < arr[i-1]){
                  dp[i] = arr[i-1]>arr[i-2]?dp[i-1]+1:2 ;
               }else{
                dp[i] = 1 ;
               }
               max = Math.max(max, dp[i]) ; 
          }
        return max ;
    }
}